package leetcode;

import util.Tree;
import util.TreeNode;

/**
 * @Project : AlgorithmLearning
 * @Package : Leetcode
 * @File : Q0226.java
 * @Author : WangRuoyu
 * @Date 2023/10/22 20:27
 */

public class Q0226 {
    public TreeNode invertTree(TreeNode root) {
        if (root == null) return null;
        TreeNode tmp = root.left;
        root.left = root.right;
        root.right = tmp;
        invertTree(root.left);
        invertTree(root.right);
        return root;
    }

    public static void main(String[] args) {
        Q0226 sl = new Q0226();
        String[] tree = {"2", "1", null, null, "3", null, null};
        TreeNode root = Tree.createTreeByPreorder(tree);
        Tree.preorderTraversal(sl.invertTree(root));
    }
}